//
//  TableViewCell.m
//  SimpleHappy
//
//  Created by lanou on 15/11/24.
//  Copyright (c) 2015年 RockyFung. All rights reserved.
//

#import "TableViewCell.h"
#import "Define.h"
#import "UIImageView+WebCache.h"
@interface TableViewCell()
@property(nonatomic,retain)UIImageView *MyImageView;//背景图片
@property(nonatomic,retain)UILabel *title;//标题
@property(nonatomic,retain)UILabel *businessesDistritrict;//地址
@property(nonatomic,retain)UILabel *hostName;//餐厅名称
@property(nonatomic,retain)UILabel *priceNow;//现价
@property(nonatomic,retain)UILabel *originalPrice;//原价
@end
@implementation TableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{

        CGFloat width = KScreenWidth;
        CGFloat height = width*387/750;



    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        //背景图片
        self.MyImageView = [[UIImageView alloc]initWithFrame:CGRectMake(5, 0, width-10, height-5)];
        self.MyImageView.image = [UIImage imageNamed:@"jiazai.jpg"];
        [self.contentView addSubview:_MyImageView];
        //阴影图片
        UIView *bgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, width-10, height-5)];
        bgView.backgroundColor = [UIColor blackColor];
        bgView.alpha =0.3;
        bgView.userInteractionEnabled = NO;
        [self.MyImageView addSubview:bgView];
        //标题
        self.title = [[UILabel alloc]initWithFrame:CGRectMake(5, height*2/3, width-5, height/6)];
        self.title.font = [UIFont boldSystemFontOfSize:18];

        self.title.textColor = [UIColor whiteColor];
        [self.MyImageView addSubview:_title];
        //下半部的View
        UIView *myView = [[UIView alloc]initWithFrame:CGRectMake(0, height*5/6, width, height/6)];
        //餐厅名称
        self.hostName = [[UILabel alloc]initWithFrame:CGRectMake(5, 0, width*3/4-5, height/6-5)];

        self.priceNow.font = [UIFont systemFontOfSize:15*KScreenWidth/375];
        self.hostName.textColor = [UIColor whiteColor];
        self.hostName.textAlignment = NSTextAlignmentLeft;
        [myView addSubview:_hostName];
        //价格的label
        self.priceNow = [[UILabel alloc]initWithFrame:CGRectMake(width*3/4, 0, width*2/9, height/6-5)];
        self.priceNow.font = [UIFont systemFontOfSize:14*KScreenWidth/375];
        self.priceNow.textColor = [UIColor whiteColor];
        self.priceNow.textAlignment = NSTextAlignmentCenter;

        [myView addSubview:_priceNow];
        self.originalPrice = [[UILabel alloc]initWithFrame:CGRectMake(width*8/9, 0, width/9, height/6)];
        self.originalPrice.font = [UIFont systemFontOfSize:12];
        self.originalPrice.textColor = [UIColor whiteColor];

        self.originalPrice.textAlignment =NSTextAlignmentCenter;
//          删除线
        UIView *deleteView = [[UIView alloc]initWithFrame:CGRectMake(0, self.originalPrice.bounds.size.height/2, width/9, 2)];
        deleteView.backgroundColor = [UIColor redColor];
        [self.originalPrice addSubview:deleteView];
        [myView addSubview:_originalPrice];
        deleteView.hidden = YES;
        [self.MyImageView addSubview:myView];
    }
    return self;
}
- (void)setReserveModel:(ReserveModel *)reserveModel
{
    _reserveModel = reserveModel;
    [self.MyImageView sd_setImageWithURL:[NSURL URLWithString:reserveModel.picUrl]];
    self.title.text = reserveModel.title;
    if (reserveModel.businessesDistrict==nil)
    {
        self.hostName.text = reserveModel.hostName;
    }
    else
    {
    self.hostName.text = [NSString stringWithFormat:@"%@ | %@",reserveModel.businessesDistrict,reserveModel.hostName];
    }
    if (self.originalPrice==nil)
    {
        self.originalPrice.hidden = YES;
    }
//    self.originalPrice.text =reserveModel.Price;
    self.priceNow.text =reserveModel.priceStr;
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
